<template>
  <div>
    <div class="my_die">
      <div>
        <span>我的</span>
      </div>
      <div>
        <div>
          <img :src="user.info_avatar" alt mode="aspectFill" />
          <span>{{user.info_nick}}</span>
          <img
            src="https://www.zhaoshengku.net/v.png"
            alt
            class="v_imgsrc"
            v-if="user.info_type==4"
          />
        </div>
        <div @click="myhome_to">
          <span>个人主页</span>
          <img src="http://www.zhaoshengku.net/wx-xz.png" alt />
        </div>
      </div>
      <div>
        <div v-for="(item,index) in fromDivVal" :key="index" @click="navgiyTo(index)">
          <div>
            <img :src="item.imgSrc" alt />
          </div>
          <div>
            <span>{{item.name}}</span>
            <img src="http://www.zhaoshengku.net/wx-xz.png" alt />
          </div>
        </div>
        <div>
          <div>
            <img src="http://www.zhaoshengku.net/wx-dh.png" alt />
          </div>
          <div @click="phone">
            <span>联系我们</span>
            <span>0351-7331314</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      user: {
        info_addr: "",
        info_phone: "",
        info_type: "",
        info_subtype: "",
        info_nick: "",
        state: "",
        info_avatar: ""
      },
      hraderImg: "http://www.zhaoshengku.net/wx-%E6%A4%AD%E5%9C%86%201.png",
      fromDivVal: [],
      yemianName: [
        "InformationCenter",
        "basedataFriends",
        "EditProfile",
        "WebmasterApplication",
        "RegistrationCenter",
        "bindonAccount",
        "Centerofconcern",
        "FortuneCenter",
        "setFocus",
        "FeedbackHelp"
      ],
      yemianNameEduca: [
        "InformationCenter",
        "basedataFriends",
        "EditProfileEducat",
        "WebmasterApplication",
        "RegistrationCenter",
        "CollaboratingCentres",
        "bindonAccount",
        "Centerofconcern",
        "FortuneCenter",
        "setFocus",
        "FeedbackHelp"
      ],
      yemianNameParents: [
        "InformationCenter",
        "myhomeParents",
        "myhomeParents",
        "setFocusFriends",
        "InviteFriends",
        "FeedbackHelp"
      ],
      codeTo: -1,
      optionId: -1,
      onload: false,
      headerCode: "",
      newarr: []
    };
  },
  methods: {
    myhome_to() {
      if (this.codeTo == 1) {
        wx.navigateTo({
          url:
            "/pages/myhomeEducat/main?id=" +
            this.optionId +
            "&expor=1&name=" +
            this.user.info_subdomain
        });
      } else if (this.codeTo == 2) {
        wx.navigateTo({
          url:
            "/pages/myhome/main?id=" +
            this.optionId +
            "&expor=1&name=" +
            this.user.info_subdomain
        });
      } else if (this.codeTo == 3) {
        wx.navigateTo({
          url:
            "/pages/myhomeParents/main?id=" +
            this.optionId +
            "&expor=1&name=" +
            this.user.info_subdomain
        });
      }
    },
    navgiyTo(e) {
      if (this.codeTo == 1) {
        wx.navigateTo({
          url:
            "/pages/" +
            this.yemianNameEduca[e] +
            "/main?inf_type=" +
            this.user.info_type
        });
        // if (e == 2 || this.$store.state.myxinxi.info_verified == 1) {
        //   wx.showToast({
        //     title: "认证成功，等待系统确认！",
        //     icon: "true",
        //     duration: 1000,
        //     mask: true
        //   });
        // }
      }
      if (this.codeTo == 2) {
        wx.navigateTo({
          url:
            "/pages/" +
            this.yemianName[e] +
            "/main?inf_type=" +
            this.user.info_type
        });
      }
      if (this.codeTo == 3) {
        wx.navigateTo({
          url:
            "/pages/" +
            this.yemianNameParents[e] +
            "/main?inf_type=" +
            this.user.info_type
        });
      }
    },
    getUserInfo() {
      this.fromDivVal = this.newarr;
      var _this = this;
      this.fromDivVal = [];
      wx.showToast({
        title: "",
        icon: "loading"
      });
      var token = wx.getStorageSync("koken");
      var headerCode = "Bearer " + token;

      wx.request({
        url: "https://api.zhaoshengku.net/index/member/getinfo",
        method: "POST",
        header: {
          Authorization: headerCode,
          "content-type": "application/x-www-form-urlencoded"
        },
        success: res => {
          if (res.data.code === 200) {
            _this.user = res.data.data;
            _this.$store.state.myxinxi = _this.user;
            _this.optionId = _this.user.info_member_id;
            if (_this.user.info_type == 4) {
              _this.codeTo = 1;
            } else if (_this.user.info_type == 5) {
              _this.codeTo = 2;
            } else if (_this.user.info_type == 6) {
              _this.codeTo = 3;
            }
            _this.fromDivVal[0] = {
              imgSrc:
                "http://www.zhaoshengku.net/wx-%E4%BF%A1%E6%81%AF%20%E6%8B%B7%E8%B4%9D%206.png",
              name: "信息中心"
            };
            if (_this.codeTo === 1) {
              _this.fromDivVal[_this.fromDivVal.length] = {
                imgSrc: "http://www.zhaoshengku.net/wx-jibenziliao.png",
                name: "基本资料"
              };
              _this.fromDivVal[_this.fromDivVal.length] = {
                imgSrc:
                  "http://www.zhaoshengku.net/wx-%E5%9C%86%E8%A7%92%E7%9F%A9%E5%BD%A2%208.png",
                name: "认证中心"
              };
              _this.fromDivVal[_this.fromDivVal.length] = {
                imgSrc: "http://www.zhaoshengku.net/wx-wzzt.png",
                name: "站长申请"
              };
              _this.fromDivVal[_this.fromDivVal.length] = {
                imgSrc: "http://www.zhaoshengku.net/wx-%E6%8A%A5%E5%90%8D.png",
                name: "报名中心"
              };

              _this.fromDivVal[_this.fromDivVal.length] = {
                imgSrc: "http://www.zhaoshengku.net/wx-hezuohuoban.png",
                name: "合作中心"
              };

              _this.fromDivVal[_this.fromDivVal.length] = {
                imgSrc: "http://www.zhaoshengku.net/wx-sjhtb.png",
                name: "账号绑定"
              };

              _this.fromDivVal[_this.fromDivVal.length] = {
                imgSrc: "http://www.zhaoshengku.net/wx-yq.png",
                name: "关注中心"
              };
              _this.fromDivVal[_this.fromDivVal.length] = {
                imgSrc: "http://www.zhaoshengku.net/wx-qb.png",
                name: "财富中心"
              };
              _this.fromDivVal[_this.fromDivVal.length] = {
                imgSrc: "http://www.zhaoshengku.net/wx-%E8%AE%BE%E7%BD%AE.png",
                name: "设置中心"
              };
            } else if (_this.codeTo === 2) {
              _this.fromDivVal[_this.fromDivVal.length] = {
                imgSrc: "http://www.zhaoshengku.net/wx-jibenziliao.png",
                name: "基本资料"
              };
              _this.fromDivVal[_this.fromDivVal.length] = {
                imgSrc:
                  "http://www.zhaoshengku.net/wx-%E5%9C%86%E8%A7%92%E7%9F%A9%E5%BD%A2%208.png",
                name: "认证中心"
              };
              _this.fromDivVal[_this.fromDivVal.length] = {
                imgSrc: "http://www.zhaoshengku.net/wx-wzzt.png",
                name: "站长申请"
              };
              _this.fromDivVal[_this.fromDivVal.length] = {
                imgSrc: "http://www.zhaoshengku.net/wx-%E6%8A%A5%E5%90%8D.png",
                name: "报名中心"
              };

              _this.fromDivVal[_this.fromDivVal.length] = {
                imgSrc: "http://www.zhaoshengku.net/wx-sjhtb.png",
                name: "账号绑定"
              };

              _this.fromDivVal[_this.fromDivVal.length] = {
                imgSrc: "http://www.zhaoshengku.net/wx-yq.png",
                name: "关注中心"
              };
              _this.fromDivVal[_this.fromDivVal.length] = {
                imgSrc: "http://www.zhaoshengku.net/wx-qb.png",
                name: "财富中心"
              };
              _this.fromDivVal[_this.fromDivVal.length] = {
                imgSrc: "http://www.zhaoshengku.net/wx-%E8%AE%BE%E7%BD%AE.png",
                name: "设置中心"
              };
            } else if (_this.codeTo === 3) {
              _this.fromDivVal[_this.fromDivVal.length] = {
                imgSrc: "http://www.zhaoshengku.net/wx-%E6%8A%A5%E5%90%8D.png",
                name: "报名中心"
              };
              _this.fromDivVal[_this.fromDivVal.length] = {
                imgSrc: "http://www.zhaoshengku.net/wx-yq.png",
                name: "关注列表"
              };
              _this.fromDivVal[_this.fromDivVal.length] = {
                imgSrc: "http://www.zhaoshengku.net/wx-qb.png",
                name: "设置中心"
              };
              _this.fromDivVal[_this.fromDivVal.length] = {
                imgSrc: "http://www.zhaoshengku.net/wx-haoyouone.png",
                name: "邀请好友"
              };
            }

            _this.fromDivVal[_this.fromDivVal.length] = {
              imgSrc: "http://www.zhaoshengku.net/wx-%E5%8F%8D%E9%A6%88.png",
              name: "反馈与帮助"
            };
            wx.hideToast();
          } else if (res.data.code == 40003) {
            wx.showToast({
              title: "访问过于频繁请稍后重试！",
              icon: "none",
              duration: 2500
            });
            wx.reLaunch({
              url: "/pages/Frequentvisits/main"
            });
          } else {
            wx.showToast({
              title: "登录凭证失效！",
              icon: "none",
              duration: 2500
            });
            setTimeout(function() {
              wx.navigateTo({
                url: "/pages/loginRegister/main"
              });
            }, 1500);
          }
        },
        fail: res => {
          console.log(res);
          if (res.errMsg) {
            wx.showToast({
              title: "请检查网络连接！",
              icon: "none",
              duration: 1500
            });
          }
        }
      });

      return token;
    },
    onShows() {
      console.log(this.$store.state.myxinxi);
      // console.log(this.user);
      var _this = this;
      // if (this.fromDivVal.length == 0 && this.onload == true ) {
      //   _this.getUserInfo();
      // }
      if (
        (this.user.info_nick != this.$store.state.myxinxi.info_nick &&
          this.onload == true) ||
        (_this.fromDivVal.length == 0 && this.onload == true)
      ) {
        _this.getUserInfo();
      }
      this.user = this.$store.state.myxinxi;
      wx.stopPullDownRefresh();
    },
    phone() {
      wx.makePhoneCall({
        phoneNumber: "0351-7331314" //仅为示例，并非真实的电话号码
      });
    }
  },
  mounted() {
    // 设置头
    wx.setNavigationBarTitle({
      title: "我的"
    });
  },
  onLoad() {
    var _this = this;
    // 验证token
    var headerCode;

    headerCode = "Bearer " + wx.getStorageSync("koken");
    this.headerCode = headerCode;
    wx.request({
      url: "https://api.zhaoshengku.net/index/login/verifytoken",
      method: "POST",
      header: {
        Authorization: headerCode,
        "content-type": "application/x-www-form-urlencoded"
      },
      success: res => {
        if (res.data.code === 200) {
          wx.showToast({
            title: "",
            icon: "loading"
          });
          this.fromDivVal = [];
          _this.getUserInfo();
        } else if (res.data.code == 40003) {
          wx.showToast({
            title: "访问过于频繁请稍后重试！",
            icon: "none",
            duration: 2500
          });
          wx.reLaunch({
            url: "/pages/Frequentvisits/main"
          });
        } else {
          wx.showToast({
            title: "未登录！",
            icon: "none",
            duration: 2500
          });
          setTimeout(function() {
            wx.navigateTo({
              url: "/pages/loginRegister/main"
            });
          }, 1000);
        }
        _this.onload = true;
      },
      fail: res => {
        console.log(res);
        if (res.errMsg) {
          wx.showToast({
            title: "请检查网络连接！",
            icon: "none",
            duration: 1500
          });
        }
      }
    });
  },
  onShow() {
    this.onShows();
  },
  onPullDownRefresh() {
    this.onShows();
  }
};
</script>

<style scoped>
span {
  font-family: PingFangSC-Regular, sans-serif;
}
.my_die > div:nth-child(1) {
  width: 100%;
  height: 271rpx;
  background: url("http://www.zhaoshengku.net/wx-%E7%9F%A9%E5%BD%A2%20%283%29.png")
    center center no-repeat;
  background-size: 100% 100%;
  box-sizing: border-box;
  display: flex;
  justify-content: space-between;
  padding: 90rpx 30rpx 0 30rpx;
}

.my_die > div:nth-child(1) > span {
  font-size: 36rpx;
  font-weight: 300;
  color: rgba(255, 255, 255, 1);
}

.my_die > div:nth-child(1) > img {
  width: 46rpx;
  height: 55rpx;
}

.my_die {
  position: relative;
}

.my_die > div:nth-child(2) {
  position: absolute;
  width: 738rpx;
  height: 212rpx;
  margin: 0 auto;
  background: url("http://www.zhaoshengku.net/wx-txbj.png") center center
    no-repeat;
  background-size: 100% 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 85rpx;
  padding-right: 106rpx;
  box-sizing: border-box;
  top: 193rpx;
  left: 6rpx;
}

.my_die > div:nth-child(2) > div:nth-child(1) {
  display: flex;
  align-items: center;
  position: relative;
}

.my_die > div:nth-child(2) > div:nth-child(1) > img {
  width: 110rpx;
  height: 110rpx;
  margin-right: 11rpx;
}
.my_die > div:nth-child(2) > div:nth-child(1) > .v_imgsrc {
  width: 50rpx;
  height: 50rpx;
  border-radius: 50%;
  position: absolute;
  top: 62rpx;
  left: 74rpx;
}
.my_die > div:nth-child(2) > div:nth-child(1) > span {
  font-size: 30rpx;
  font-weight: bold;
  color: rgba(0, 0, 0, 1);
  width: 200rpx;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.my_die > div:nth-child(2) > div:nth-child(2) > span {
  font-size: 30rpx;
  font-weight: bold;
  color: rgba(0, 0, 0, 1);
}

.my_die > div:nth-child(2) > div:nth-child(2) > img {
  margin-left: 11rpx;
  width: 12rpx;
  height: 22rpx;
}

.my_die > div:nth-child(3) {
  margin-top: 130rpx;
}

.my_die > div:nth-child(3) > div {
  width: 100%;
  height: 50px;
  padding-left: 31rpx;
  padding-right: 32rpx;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-sizing: border-box;
}

.my_die > div:nth-child(3) > div > div:nth-child(1) > img {
  width: 38rpx;
  height: 37rpx;
  margin-right: 31rpx;
  margin-top: 10rpx;
}

.my_die > div:nth-child(3) > div > div:nth-child(2) {
  height: 100rpx;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1rpx solid #dddddd;
  flex: 1;
}

.my_die > div:nth-child(3) > div > div:nth-child(2) > span {
  font-size: 30rpx;
  font-weight: 400;
  color: rgba(0, 0, 0, 1);
}

.my_die > div:nth-child(3) > div > div:nth-child(2) > img {
  width: 12rpx;
  height: 22rpx;
}

.my_die
  > div:nth-child(3)
  > div:last-child
  > div:nth-child(2)
  > span:last-child {
  font-size: 30rpx;
  font-weight: 400;
  color: rgba(34, 151, 212, 1);
}
</style>
